#include "stdafx.h"
#include "DeleteAllDataInInc.h"

DeleteAllDataInInc::DeleteAllDataInInc()
{
}

DeleteAllDataInInc::~DeleteAllDataInInc()
{
}

bool DeleteAllDataInInc::IsFileValid(CString fileName)
{
	CString ext = PublicFunc::GetFileExtension(fileName);
	if (ext == _T("h"))
	{
		return true;
	}

	return false;
}

void DeleteAllDataInInc::DeleteFunction(CString fileName)
{
	PublicFunc::ReadSourceFile(fileName, m_csReadlines);
	int ipostart1 = -1;
	int ipostart2 = -1;

		AddFileToNote(fileName);

		int idhead = 0, idtail = 0;

		CFileFind finder;
		BOOL bResult = finder.FindFile(fileName);
		if (bResult)
		{
			DeleteFile(fileName);
		}
		try
		{
			CString str;
			CStdioFile file(fileName, CFile::modeCreate | CFile::modeWrite);			file.SetLength(0);

			int num = this->m_csReadlines.GetSize();
			for (int k = 0; k < num; k++)
			{
				CString string = m_csReadlines[k], string1;
				if (PublicFunc::IsStrHasStr(string, _T("dataIn(DcDataFiler"), idhead, idtail) ||
					PublicFunc::IsStrHasStr(string, _T("dataOut(DcDataFiler"), idhead, idtail))
				{
					string = _T("//") + string;
				}

				file.WriteString(string);

				if (k != num - 1)
				file.WriteString("\n");
			}
			file.Close();
		}
		catch (CFileException* e)
		{
			e->ReportError();
			e->Delete();

			return;
		}
}

bool DeleteAllDataInInc::Do(CString fileName)
{
	DeleteFunction(fileName);

	return true;
}
